Discover   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 38
dl 0
loc 92
c 0
b 0
f 0
rs 10

6 Functions

Rating   Name   Duplication   Size   Complexity  
A withoutGenres 0 9 1
A withCompanies 0 8 1
A withGenres 0 9 1
A movie 0 10 1
A tv 0 9 1
A mergeParameters 0 19 4
1
import { BaseEndpoint, QueryParameters } from './baseEndpoint';
2
import {
3
    DiscoverMovieResponse,
4
    DiscoverTVResponse,
5
} from '../interfaces/discover';
6
7
/**
8
 * Discover Endpoint Class
9
 */
10
export class Discover extends BaseEndpoint {
11
12
    /**
13
     * We want these genres
14
     * @var [number] | null
15
     */
16
    private onlyTheseGenres: [number] | null = null;
17
18
    /**
19
     * We dont want these genres
20
     * @var [number] | null
21
     */
22
    private withoutTheseGenres: [number] | null = null;
23
24
    /**
25
     * We want only these companies
26
     * @var [number] | null
27
     */
28
    private onlyTheseCompanies: [number] | null = null;
29
30
    /**
31
     * Get media only with these genres
32
     * @param { [number] } genres
33
     * @return Discover
34
     */
35
    withGenres(genres: [number]): Discover {
36
        this.onlyTheseGenres = genres;
37
        return this;
38
    }
39
40
    /**
41
     * Exclude media with these genres
42
     * @param { [number] } genres
43
     * @return Discover
44
     */
45
    withoutGenres(genres: [number]): Discover {
46
        this.withoutTheseGenres = genres;
47
        return this;
48
    }
49
50
    /**
51
     * Get media produced by only these companies
52
     * @param companies
53
     */
54
    withCompanies(companies: [number]): Discover {
55
        this.onlyTheseCompanies = companies;
56
        return this;
57
    }
58
59
    /**
60
     * Discover movies by different types of data like average rating, number of votes, genres and certifications.
61
     * You can get a valid list of certifications from the certifications list method.
62
     * @param { QueryParameters } parameters
63
     * @return { Promise<ConfigurationAPIResponse> }
64
     * @see https://developers.themoviedb.org/3/discover/movie-discover
65
     */
66
    public async movie(parameters: QueryParameters = {}): Promise<DiscoverMovieResponse> {
67
        return this.sendGetRequest(`discover/movie`, this.mergeParameters(parameters));
68
    }
69
70
    /**
71
     * Discover TV shows by different types of data like average rating, number of votes, genres, the network they aired on and air dates.
72
     * @param { QueryParameters } parameters
73
     * @return { Promise<ConfigurationAPIResponse> }
74
     * @see https://developers.themoviedb.org/3/discover/tv-discover
75
     */
76
    public async tv(parameters: QueryParameters = {}): Promise<DiscoverTVResponse> {
77
        return this.sendGetRequest('discover/tv', this.mergeParameters(parameters));
78
    }
79
80
    /**
81
     * Merge provided parameters with parameters created with class methods
82
     * @param parameters
83
     */
84
    protected mergeParameters(parameters: QueryParameters): QueryParameters {
85
        if (this.onlyTheseGenres !== null) {
86
            parameters.with_genres = this.onlyTheseGenres.join(',');
87
        }
88
89
        if (this.withoutTheseGenres !== null) {
90
            parameters.without_genres = this.withoutTheseGenres.join(',');
91
        }
92
93
        if (this.onlyTheseGenres !== null) {
94
            parameters.with_companies = this.onlyTheseCompanies.join(',');
95
        }
96
97
        return parameters;
98
    }
99
100
}
101